package com.tuling.iocbeanlifecicle;

import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by xsls on 2019/8/15.
 */
// @Configuration
public class MainStarter {

	public static void main(String[] args) throws Exception {
		// 加载spring上下文
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class);
		if (true) {

			Object car = context.getBean("car");
			Method getName = car.getClass().getMethod("getName");
			System.out.println("-------------------main--------------------");
			System.out.println(getName.invoke(car));
			Field tank = car.getClass().getDeclaredField("tank");
			tank.setAccessible(true);
			System.out.println(tank.get(car));
		}
		if (true) {

			Object car = context.getBean("car");
			Method getName = car.getClass().getMethod("getName");
			System.out.println("-------------------main--------------------");
			System.out.println(getName.invoke(car));
			Field tank = car.getClass().getDeclaredField("tank");
			tank.setAccessible(true);
			System.out.println(tank.get(car));
		}
	}







	/*public static void main(String[] args) {
		List<Tank> list=new ArrayList<>();
		Tank tank2=new Tank();
		tank2.setName("坦克2号");
		tank2.setIndex(2);
		list.add(tank2);

		Tank tank=new Tank();
		tank.setName("坦克1号");
		tank.setIndex(1);
		list.add(tank);

		*//*list.sort((o1, o2) -> {
			return Integer.compare(o1.getIndex(), o2.getIndex());
		});*//*

		list.forEach(tank1 -> System.out.println(tank1.getIndex()));
	}*/
}
